"""
终于简单懂了暴力深搜怎么写了~
一种感觉悟出来了就一通百通~
初步入门暴力杯
往下还是想学学怎么用好动态规划
"""


# 全局变量
record = []


def package_dfs(values, weights, value, weight, W, deep, n):
    if deep == n:
        if weight <= W:
            # print(value)
            record.append(value)
        return
    # 有放进去
    package_dfs(values, weights, value+values[deep], weight+weights[deep], W, deep+1, n)
    # 没有放进去
    package_dfs(values, weights, value, weight, W, deep+1, n)


def resolution1():
    n = int(input())
    weight_list = [0] * n
    value_list = [0] * n
    for i in range(n):
        args = input().strip()
        args = list(map(int, args.split(" ")))
        weight_list[i] = args[0]
        value_list[i] = args[1]
    q = int(input())
    for _ in range(q):
        value = 0
        weight = 0
        W = int(input())
        record.clear()
        package_dfs(value_list, weight_list, value, weight, W, 0, n)
        # print(record)
        print(max(record))


def resolution2():
    pass


if __name__ == '__main__':
    # DFS
    # resolution1()
    # DP
    resolution2()